﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Globalization;

namespace 天机万年历.自定义控件
{
    public partial class TimeShower : TextBox
    {
        public TimeShower()
        {
            base.Text = time.ToString();
        }

        [Browsable(false)]
        public override string Text { get; set; }

        private Time time = new Time();
        [TypeConverter(typeof(StringConverter))]
        public Time Time
        {
            get => time;
            set
            {
                if (time != value)
                {
                    time = value;
                    base.Text = time.ToString();
                }
            }
        }

        public class TimeConverter : StringConverter
        {
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                return true;
            }
            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            {
                return value.ToString();
            }
        }
    }
}
